package org.deadline.model.user;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.baseapp.BaseEntity;
import org.deadline.model.config.SecurityQuestion;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

@Entity
public class PersonSecurityQuestion extends BaseEntity  implements Serializable {

    @NotNull
    @ManyToOne
    private Person person;

    @NotNull
    @ManyToOne
    private SecurityQuestion securityQuestion;

    @NotNull
    @Size(min = 3, max = 30)
    private String answer;

	@Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="person_security_question_seq_gen",sequenceName="person_security_question_seq")
	@GeneratedValue(generator="person_security_question_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

	
	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static PersonSecurityQuestion fromJsonToPersonSecurityQuestion(String json) {
        return new JSONDeserializer<PersonSecurityQuestion>().use(null, PersonSecurityQuestion.class).deserialize(json);
    }

	public static String toJsonArray(Collection<PersonSecurityQuestion> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<PersonSecurityQuestion> fromJsonArrayToPersonSecurityQuestions(String json) {
        return new JSONDeserializer<List<PersonSecurityQuestion>>().use(null, ArrayList.class).use("values", PersonSecurityQuestion.class).deserialize(json);
    }

	private static final long serialVersionUID = 1L;

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	public Person getPerson() {
        return this.person;
    }

	public void setPerson(Person person) {
        this.person = person;
    }

	public SecurityQuestion getSecurityQuestion() {
        return this.securityQuestion;
    }

	public void setSecurityQuestion(SecurityQuestion securityQuestion) {
        this.securityQuestion = securityQuestion;
    }

	public String getAnswer() {
        return this.answer;
    }

	public void setAnswer(String answer) {
        this.answer = answer;
    }

	public Long getId() {
	    return this.id;
	}

	public void setId(Long id) {
	    this.id = id;
	}

	}
